home *** CD-ROM | disk | FTP | other *** search
/ Aminet 8 / Aminet 8 (1995)(GTI - Schatztruhe)[!][Oct 1995].iso / Aminet / util / boot / RNDBackdrop.lha / RNDBackdrop / RndBackdrop next >
Text File  |  1995-08-08  |  3KB  |  115 lines

  1. /*  RndBackdrop 1.0 - Copy a random backdrop into a certain file
  2. **                    optionally reload WBPattern
  3. **
  4. **  By Reinhard Katzmann
  5. **/
  6. version='$VER: rndbackdrop 1.0 (8.8.94)
  7. '
  8. SIGNAL ON BREAK_D
  9. SIGNAL ON BREAK_C
  10.  
  11. OPTIONS RESULTS
  12.  
  13. if ~show('L', 'rexxdossupport.library') then    /* Just for ReadArgs() */
  14.     call addlib('rexxdossupport.library',0,-30)
  15.  
  16. if ~show('L', 'rexxarplib.library') then        /* For Getenv() */
  17.     call addlib('rexxarplib.library',0,-30)     
  18.  
  19. /* Parse arguments */
  20. /*  Usage: rndbackdrop TO,Infile/K,TMPFile/K,TMPPrefs/K,RELOAD/S,MSG/S */
  21.  
  22. parse arg args
  23.  
  24. template = 'TO,Infile/K,TMPFile/K,TMPPrefs/K,RELOAD/S,MSG/S'
  25.  
  26. WBBDC=Getenv("WBBACKDROPCMD") /* Use this for your personal WBBackdrop Command */
  27. if WBBDC=='' then WBBDC='WBPattern use' /* Do not load WBPattern GUI */
  28. TO='dh0:t/bdpic'
  29. Infile='dh0:t/backdrops'
  30. TMPFile='dh0:t/oldpic'
  31. TMPPrefs='dh0:t/tmpprefs'  /* Must include the name of TMPFile !! */
  32. RELOAD=0
  33. MSG=0  /* Switch MSG if you want to know what picture has been selected */
  34.  
  35. if (args=='?') then do
  36.     writech(stdout,template': ')
  37.     parse pull moreargs
  38.     if (moreargs=='?') then do
  39.         say "rndfile"
  40.         say "Written by Reinhard Katzmann"
  41.         say version
  42.         say ""
  43.         say "Usage: rndbackdrop "template
  44.         say ""
  45.         say "Examples:"
  46.         say "    RX rndbackdrop"
  47.         say "        load the default backdrop list, copies it to default rndbackdrop"
  48.         say "        defaults are: dh0:t/backdrops (file list), dh0:t/bdpic (picture)"
  49.         say ""
  50.         say "    RX rndbackdrop sys:prefs/presets/mypic Infile=sys:prefs/presets/piclist"
  51.         say "        Select a random pic from piclist and copy is to mypic"
  52.         say ""
  53.         say "    RX rndbackdrop TMPFile=dh0:t/mytmp TMPPrefs=dh0:t/myprefs RELOAD"
  54.         say "        Select random pic as in first example, but notifies WBPattern"
  55.         say "        to use the new picture, tmp file will be deleted afterwards"
  56.         exit
  57.     end
  58.     else args=moreargs
  59. end
  60.  
  61. ReadArgs(args,template)
  62.  
  63. /* Main Program */
  64.  
  65. if (~exists(Infile)) then do
  66.   say "Infile Pic List "Infile" does not exists."
  67.   exit
  68. end
  69.  
  70. /* Open and read backdrop picture list */
  71.  
  72. if (~open('fp',Infile,'R')) then do
  73.   say "Could not open file "Infile" for reading."
  74.   exit
  75. end
  76.  
  77. numfiles=0
  78. do until EOF('fp')
  79.   numfiles=numfiles+1
  80.   thefile.numfiles=readln('fp')
  81. end
  82.  
  83. if reload==1 then do  /* Rename the old pic, used later by old prefs */
  84.   if (~exists(TO)) then do
  85.     say "Old picture "TO" is missing, no reload possible"
  86.     exit
  87.   end
  88.   ADDRESS COMMAND 'rename "'TO'" "'TMPFile'"'
  89. end
  90.  
  91. /* Now we have read the pic list, we may handle it */
  92. if numfiles>0 then do
  93.   rnum = random(1,numfiles,random(1,100,(TIME(SECONDS))))
  94.   name=thefile.rnum
  95.   ADDRESS COMMAND 'copy "'name'" "'TO'"'
  96.   if MSG==1 then say "Backdrop chosen was "name"."
  97. end
  98. else do
  99.   say "File "Infile" is empty."
  100.   exit
  101. end
  102.  
  103. if reload==1 then do
  104.   ADDRESS COMMAND WBBDC' "'TMPPrefs'"' /* Load the tmp prefs (without picname) */
  105.   ADDRESS COMMAND WBBDC' envarc:sys/WBPattern.prefs' /* Öpad the new pic */
  106.   ADDRESS COMMAND 'WAIT 1' /* Necessary, because else sometimes TMPfile can't be deleted */
  107.   ADDRESS COMMAND 'Delete "'TMPFile'"' /* Delete tmp file */
  108. end
  109.  
  110. BREAK_D:
  111. exit
  112.  
  113. BREAK_C:
  114. exit
  115.